﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ZBZH_Manage_Order.PublicMethod
{
    public class ZhiFu
    {
        /// <summary>
        /// 字符串去"
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string clzf(string str)
        {
            string[] s = str.Split('"');
            string re = "";
            for (int i = 0; i < s.Length; i++)
            {
                re += s[i];
            }
            return re;
        }
        /// <summary>
        /// 入日期返INT
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string clrq(string str)
        {
            if (str.Trim().Length == 0) { return ""; }
            string[] s = DateTime.Parse(str).ToString("yyyy-MM-dd").Split('-');
            string re = "";
            for (int i = 0; i < s.Length; i++)
            {
                re += s[i];
            }
            re += "0000";
            return re;
        }

        public string DateFormat(string str)
        {//时间日期格式转换 2014/1/1 转换为 201401010000
            if (str.Trim().Length == 0) { return ""; }
            else
            {

                string[] s = str.Split('/');
                string result = s[0];
                if (s[1].Trim().Length == 1)
                {
                    result += "0" + s[1];
                }
                else
                {
                    result += s[1];
                }
                if (s[2].Trim().Length == 1)
                {
                    result += "0" + s[2];
                }
                else
                {
                    result += s[2];
                }
                result += "0000";
                return result;
            }

        }
        public string DateFormatStr(string str)
        {   //时间日期格式转换 2014/1/1 转换为 2014/01/01
            if (str.Trim().Length == 0) { return ""; }
            else
            {

                string[] s = str.Split('/');
                string result = s[0] + "/";
                if (s[1].Trim().Length == 1)
                {
                    result += "0" + s[1] + "/";
                }
                else
                {
                    result += s[1] + "/";
                }
                if (s[2].Trim().Length == 1)
                {
                    result += "0" + s[2];
                }
                else
                {
                    result += s[2];
                }

                return result;
            }
        }
        public string TimeFormat(string str)
        { //时分格式转换 1:2 转换 0102  
            if (str.Trim().Length == 0) { return ""; }
            else
            {
                string[] s = str.Split(':');
                string result = "";
                if (s[0].Trim().Length == 1)
                {
                    result += "0" + s[0];
                }
                else
                {
                    result += s[0];
                }
                if (s[1].Trim().Length == 1)
                {
                    result += "0" + s[1];
                }
                else
                {
                    result += s[1];
                }
                return result;
            }

        }
        public string addTimeFormat(string str)
        { //时分格式转换 102 转换 1:02   1303->13:03
            if (str.Trim().Length == 0) { return ""; }
            else
            {
                string result = "";

                if (str.Length == 3)
                {
                    result = str.Substring(0, 1) + ":" + str.Substring(1, 2);
                }
                else if (str.Length == 4)
                {
                    result = str.Substring(0, 2) + ":" + str.Substring(2, 2);
                }
                return result;
            }
        }
        public string addDateFormat(string str)
        {//时间日期格式转换 201401010000 转换为 2014/01/01,去掉日期的时分秒，保留年月日
            if (str.Trim().Length != 0)
            {
                str = str.Substring(0, 8);
                return str.Substring(0, 4) + "/" + str.Substring(4, 2) + "/" + str.Substring(6, 2);
            }
            return "";
        }

        public string DecimalStr(double d)
        {//保留百分比后得小数点为2位   0.3->30%  0.2323->23.23%  0.23344444->23.34%  0.004666->0.47%
            string str = (d * 100).ToString();
            if (!str.Contains(".")) { return str + "%"; }
            string result = "";
            string[] res = str.Split('.');
            result += res[0] + ".";
            if (res[1].Length <= 2)
            {
                result += res[1];
            }
            else
            {
                //四舍五入
                int d2 = Convert.ToInt32(res[1].Substring(2, 1));
                if (d2 >= 5)
                {
                    int d1 = Convert.ToInt32(res[1].Substring(1, 1)) + 1;
                    result += res[1].Substring(0, 1) + d1.ToString();
                }
                else
                {
                    result += res[1].Substring(0, 2);
                }
            }
            return result + "%";


        }
        /// <summary>
        /// 入字符返ID
        /// </summary>
        /// <param name="sta"></param>
        /// <returns></returns>
        public string clstat(string sta)
        {
            string id = "";
            if (sta == "未受理")
            {
                id = "0";
            }
            if (sta == "已受理")
            {
                id = "1";
            }
            if (sta == "暂停")
            {
                id = "2";
            }
            if (sta == "处理完成")
            {
                id = "3";
            }
            if (sta == "异常关闭")
            {
                id = "4";
            }
            if (sta == "报修人关闭")
            {
                id = "5";
            }
            if (sta == "放弃维修")
            {
                id = "6";
            }
            return id;
        }
        /// <summary>
        /// 入ID返字符
        /// </summary>
        /// <param name="sta"></param>
        /// <returns></returns>
        public string clstatid(string sta)
        {
            string id = "";
            if (sta == "0")
            {
                id = "未受理";
            }
            if (sta == "1")
            {
                id = "已受理";
            }
            if (sta == "2")
            {
                id = "暂停";
            }
            if (sta == "3")
            {
                id = "处理完成";
            }
            if (sta == "4")
            {
                id = "异常关闭";
            }
            if (sta == "5")
            {
                id = "报修人关闭";
            }
            if (sta == "6")
            {
                id = "放弃维修";
            }
            return id;
        }
        #region 是否为拼音
        public bool IsPinYin(string str)
        {
            System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9A-Za-z]+$");
            return reg1.IsMatch(str);
        }
        #endregion
        #region 是否为数字
        public bool IsNum(string str)
        {
            System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]+$");
            return reg1.IsMatch(str);
        }
        #endregion
        #region 格式化日期格式（将201403170923转换为2014/03/17 09:23)
        /// <summary>
        /// 格式化日期格式（将201403170923转换为2014/03/17 09:23)
        /// </summary>
        /// <param name="str">时间字符串（如：201403170923）</param>
        /// <returns>时间字符串（如：2014/03/17 09:23）</returns>
        public string FormatDateTime(string str)
        {
            if (str != "")
                return str.Substring(0, 4) + "/" + str.Substring(4, 2) + "/" + str.Substring(6, 2) + " " + str.Substring(8, 2) + ":" + str.Substring(10, 2);
            else
                return "";
        }
        #endregion

        #region 是否为电话号码格式
        public bool IsPhoneNum(string str)
        {
            System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^\d{11}$");
            return reg1.IsMatch(str);
        }
        #endregion
    }
}